query = function(...) {
   args = list(...)
   pars = names(args)
   if (!is.null(pars))
      args = ifelse(pars=='', as.character(args), paste(pars, args, sep='='))
   paste(args, collapse='&') }
   
subquery = function(..., operator='AND') {
   args = list(...)
   pars = names(args)
   if (!is.null(pars))
      args = ifelse(pars=='', as.character(args), sprintf('%s[%s]', args, pars))
   subquery = paste(
      lapply(args, function(component) 
         if (!inherits(component, 'subquery') | operator %in% class(component)) component
         else sprintf('(%s)', component)),
      collapse=sprintf(' %s ', operator))
   class(subquery) = c(operator, 'subquery')
   return(subquery) }

AND = function(...)
   subquery(..., operator='AND')

OR = function(...)
   subquery(..., operator='OR')
